import Vue from "vue";
import Vuex from "vuex";
import VuexPersistence from "vuex-persist";
Vue.use(Vuex);

var vueLocal = new VuexPersistence({
  // storage 存储方式  默认的是localStorage存储，可以修改成会话存储（window.sessionStorage）
  storage: window.localStorage,
});
let modules = {};

const requireAllModules = require.context("./modules", true, /\.js$/);
requireAllModules.keys().forEach((key) => {
  let module = requireAllModules(key).default;
  if (module && module.name && module.namespaced) {
    modules[module.name] = module;
  }
});

export default new Vuex.Store({
  plugins: [vueLocal.plugin],
  modules: modules,
  strict: process.env.NODE_ENV !== "production",
});
